/* cmd_basic.c
**
** Copyright 2006, Brian Swetland.  All rights reserved.
** See provided LICENSE file or http://frotz.net/LICENSE for details.
*/

#include "debugger.h"

void
cmd_connect() // connect to the debug target
{
}

void
cmd_rd(Address addr) // read one word of memory
{
    unsigned n = rd32(addr);
    if(failed()) return;

    msg("%08x: %08x\n", addr, n);
}

void
cmd_wr(Address addr, Value val) // write one word of memory
{
    wr32(addr, val);
    if(failed()) return;
    
    msg("%08x: %08x\n", addr, val);
}

void
cmd_dump(Address addr) // dump 64 words of memory
{
    unsigned x[64];
    unsigned n;

    rd32x(addr, x, 64);
    if(failed()) return;
    
    for(n = 0; n < 64; n+=4){
        msg("%08x: %08x %08x %08x %08x\n",
            addr + n * 4, x[n + 0], x[n + 1], x[n + 2], x[n + 3]);
    }
}

unsigned
disassemble_readword(unsigned addr)
{
    return rd32(addr);
}

void disassemble(unsigned addr);

void
cmd_dis(Address addr) // disassemble arm instructions
{
    unsigned n;
    for(n = 0; n < 8; n++){
        disassemble(addr + n * 4);
        if(failed()) break;
    }
}

void
cmd_halt() // stop executing user code
{
    halt();
}

void
cmd_go(Address addr) // start executing code at <addr>
{
    jump_to(addr);
}

